package com.aiju.support.mvp;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.aiju.app.config.ConfigManager;
import com.aiju.base.R;
import com.aiju.support.connetion.ConnectivityMonitor;
import com.aiju.support.connetion.ConnectivityMonitorImpl;
import com.aiju.support.lifecycle.LifecycleListener;
import com.aiju.support.proxy.DynamicProxy;
import com.aiju.utils.L;
import com.aiju.utils.T;

/**
 * @author: 佐为
 * @date: 2017-02-14 14:29
 * @version: V1.0
 * @Description: 描述
 */
public class TestMvpActivity extends BaseMvpActivity<TestView, TestP>
        implements TestView, View.OnClickListener {

    private LifecycleListener mMonitor;

    /**
     * 添加数字键盘点击事件
     */
    private void addKeyboardListener() {
     /*   ViewGroup group = (ViewGroup) findViewById(R.id.gl_keyboard);
        int count = group.getChildCount();
        for (int i = 0; i < count; i++) {
            group.getChildAt(i).setOnClickListener(this);
        }*/
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.test);


        DynamicProxy proxy = new DynamicProxy();
        Pre bind = (Pre) proxy.bind(new ab());
        bind.toast();

        mMonitor = new ConnectivityMonitorImpl(this, new ConnectivityMonitor.ConnectivityListener() {
            @Override
            public void onConnectivityChanged(boolean isConnected) {
                if (isConnected) {
                    Toast.makeText(TestMvpActivity.this, "网络连接正常", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(TestMvpActivity.this, "网络连接失败", Toast.LENGTH_SHORT).show();
                }
            }
        });

        getLifecycle().addListener(mMonitor);
        mPresenter.showHit();
        L.d(ConfigManager.version.toString());
/*        Downloader downloader=new DefaultDownLoader();
        downloader.download("http://gdown.baidu.com/data/wisegame/1ceb33a949e92da8/MMshangchang_10610.apk", ConfigManager.DIR_CACHE+"/"+"a.apk",0);
        downloader.setListener(new Downloader.OnDownloaderListener() {
            @Override
            public void onDownloadProgress(int progress) {
                L.d("progress:"+progress);
            }

            @Override
            public void onDownloadFinsh(String filePath) {
                L.d("filePath:"+filePath);
            }

            @Override
            public void onFailure(int code, String errorMessage) {
                L.d("onFailure:"+errorMessage);
            }
        });*/
    }

    @Override
    public TestP initPresenter() {
        return new TestP();
    }

    @Override
    public void showHit() {
        T.ToastShort("提示");
    }

    @Override
    public void setViewState(ViewState state, View.OnClickListener... listeners) {
        setState(state, listeners);
    }

    @Override
    public void onClick(View v) {
    /*    int i = v.getId();
        if (i == R.id.tv_pay_7) {
            T.ToastShort("7");
        }*/
    }

    public interface Pre {
        void toast();
    }

    private class ab implements Pre {

        @Override
        public void toast() {
            //T.ToastShort("测试");
            L.d("执行");
        }
    }
}
